using System;
using System.Web.UI.WebControls;
using CARMSBusiness;
using SD.LLBLGen.Pro.ORMSupportClasses;
using VitalShining.WebControls;
using CARMSData.CollectionClasses;
using CARMSData.EntityClasses;
using CARMSData.HelperClasses;

namespace CARMS.AdminTemplate
{
    [Function("Admin.ReportCategoryList")]
    public partial class ReportCategoryList : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnNewItem.Enabled = true;
                PageQueryAdapter1.PerformQuery();

                controlCondition.InitalControls("Admin.ReportCategoryList", "Report");
            }
        }

        protected override void btnNewItem_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/AdminTemplate/ReportCategoryDetail.aspx");
        }
        protected void btnSearchReport_Click(object sender, EventArgs e)
        {
            PageQueryAdapter1.PerformQuery();
        }

        protected void btnViewAll_Click(object sender, EventArgs e)
        {
            controlCondition.InitalControls("Admin.ReportCategoryList", "Report");
            PageQueryAdapter1.PerformQuery();
        }


        protected void gridReport_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                var entity = (ReportCategoryEntity)e.Row.DataItem;
                e.Row.Attributes.Add("ReportCategoryId", entity.ReportCategoryId.ToString());
            }
        }

        protected void gridReport_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "DeleteItem":
                    //if (ReportBusiness.DeleteReport(new Guid(e.CommandArgument.ToString())))
                    //{
                    //    PageQueryAdapter1.PerformQuery();
                    //    base.Alert("Successfully deleted!");
                    //}
                    break;
                case "ViewItem":
                    Response.Redirect("~/AdminTemplate/ReportCategoryDetail.aspx?ReportCategoryID=" + e.CommandArgument);
                    break;
                case "ModifyProperty":
                    Response.Redirect(SiteUrls.AdminTemplate.ReportPropertyList + "?ReportCategoryID=" + e.CommandArgument);
                    break;
                    
            }
        }


        protected void gridEmployeeList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

            }
        }



        protected void PageQueryAdapter1_PerformGetPageData(object sender, PerformGetPageDataEventArgs e)
        {
            SortExpression sort;
            switch (gridReport.SortExpression)
            {
                case "ReportCategoryID":
                    sort = new SortExpression(ReportCategoryFields.ReportCategoryId | (SortOperator)(int)gridReport.SortDirection);
                    break;
                case "ReportCategoryName":
                    sort = new SortExpression(ReportCategoryFields.ReportCategoryName | (SortOperator)(int)gridReport.SortDirection);
                    break;
                case "ReportCategoryType":
                    sort = new SortExpression(ReportCategoryFields.ReportCategoryType | (SortOperator)(int)gridReport.SortDirection);
                    break;
                default:
                    sort = new SortExpression(ReportCategoryFields.CreateDate | SortOperator.Descending);
                    break;
            }

            var collection = new ReportCategoryCollection();
            collection.GetMulti((PredicateExpression)e.Condition, 0, sort, null, e.PageIndex + 1, e.PageSize);

            e.DataSource = collection;
        }


        protected void PageQueryAdapter1_PerformGetRecordCount(object sender, PerformGetRecordCountEventArgs e)
        {
            var collection = new ReportCategoryCollection();

            e.RecordCount = collection.GetDbCount((PredicateExpression)e.Condition);

        }
        protected void PageQueryAdapter1_PerformGetCondition(object sender, PerformGetConditionEventArgs e)
        {
            var condition = controlCondition.GetPredicateExpression();
          
            e.Condition = condition;
        }



    }
}
